﻿using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Json;

namespace Viby
{
    [DataContract]
    public class ServerResponse
    {
        [DataMember]
        public string type { get; set; }

        [DataMember]
        public string[] parameters { get; set; }

        public ServerResponse(string type, string[] parameters)
        {
            this.type = type;
            this.parameters = parameters;
        }

        public static string Get(string type, string[] parameters)
        {
            MemoryStream stream = new MemoryStream();
            DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(ServerResponse));
            s.WriteObject(stream, new ServerResponse(type, parameters));
            stream.Position = 0;
            StreamReader streamReader = new StreamReader(stream);
            return streamReader.ReadToEnd();
        }

        public static string Get(string type, string parameter)
        {
            return Get(type, new string[] { parameter });
        }

        public static string Get(string type)
        {
            return Get(type, new string[]{});
        }
    }
}